package net.seehealth.healthpad.dataaccess;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * 
 * @className CreatTable
 * @author 刘绍辉
 * @description TODO 建表
 * @date 2012-3-13 上午10:33:36
 */
public class CreatTable {
	public static void createtables(Context context,SQLiteDatabase db) {
		try {
			String sqll[] = new String[] {
					//数据上传表
					"create table bloodpressure (bid int not null,userID int,rdate char(30),bloodpressure numeric,diastolicpressure numeric,pulse numeric,year int,month char(10),week int,datafrom int,constraint PK_BLOODPRESSURE primary key clustered (bid))",// 建立血压计表
					"create table weight(wid int not null,userID int,rdate char(30),age int,bm numeric,visceralfat numeric,bodyfatRate numeric,bodyage int,bmi numeric,skeletalmuscleRate numeric,weight numeric,year int,month char(10),week int,datafrom int,constraint PK_WEIGHT primary key clustered (wid))", // 建立体重仪表
					"create table electrocardio (eid int not null,userID int,rdate char(30),isright char(300),howmany int,howmanysuccess int,ahrhear numeric,pr numeric,qt numeric,rvolt numeric,pvolt numeric,tvolt numeric,svolt numeric,year int,month int,week int,datafrom int,constraint PK_ELECTROCARDIO primary key clustered (eid))",// 建立心电仪表
					"create table foodrecord ( frid int not null,userID int,intake numeric,eatTime int,intakeen numeric,foodCode char(20),recordTime char(21),constraint PK_FOODRECORD primary key clustered (frid))",// 运动记录表
					"create table sportrecord (srid int not null,userID int,sportTime int,waste numeric,sportCode char(20),recordTime char(21),constraint PK_SPORTRECORD primary key clustered (srid))",//膳食记录表
					
					//"create table if not exists province (pid char(10) primary key,pname char(30))",//省份
					"create table if not exists city (cid char(10) primary key,cname char(30),pname char(30))",//城市天气表
					"create table if not exists generalphrases  (gid int auto_increment primary key ,cname char(30),gname char(100)",// 常用语表
					"",//用户信息表
					"",
					// 插入一些初始化测试数据
					// 体重仪
					"insert into weight values('A001','2012-03-01 10:06:22',55,60.5,130,120,140,150,160,80,110)",
					"insert into weight values('A002','2012-03-02 10:06:22',55,60.5,130,120,140,150,160,80,110)",
					"insert into weight values('A002','2012-03-03 10:06:22',55,60.5,130,120,140,150,160,80,110)",
					"insert into weight values('A003','2012-03-04 10:06:22',55,60.5,130,120,140,150,160,80,110)",
					"insert into weight values('A004','2012-03-05 10:06:22',55,60.5,130,120,140,150,160,80,110)",
					// 心电图
					"insert into electrocardio values('A001','2012-03-06 10:06:22','test data and demo data',10,80,120,140,150,160,80,110,90)",
					"insert into electrocardio values('A001','2012-03-07 10:06:22','test data and demo data',10,80,120,140,150,160,80,110,90)",
					"insert into electrocardio values('A001','2012-03-08 10:06:22','test data and demo data',10,80,120,140,150,160,80,110,90)",
					"insert into electrocardio values('A001','2012-03-09 10:06:22','test data and demo data',10,80,120,140,150,160,80,110,90)",
					"insert into electrocardio values('A001','2012-03-10 10:06:22','test data and demo data',10,80,120,140,150,160,80,110,90)",
					// 血压计
					"insert into bloodpressure values('A001','2012-03-11 10:06:22',80,80,30)",
					"insert into bloodpressure values('A002','2012-03-12 10:06:22',80,80,30)",
					"insert into bloodpressure values('A003','2012-03-13 10:06:22',80,80,30)",
					"insert into bloodpressure values('A004','2012-03-14 10:06:22',80,80,30)",
					"insert into bloodpressure values('A004','2012-03-15 10:06:22',80,80,30)",
					// 常用语
					"insert into generalphrases values('您好！欢迎您咨询杭州希禾网络服务!')",
					"insert into generalphrases values('可以')",
					"insert into generalphrases values('再见')" };
			for (String o : sqll) {// 循环所有SQL语句，进行建表和初始化一些数据操作
				createTable(db, o);
			}
			//db.close();//关闭数据库
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void createTable(SQLiteDatabase db,String sql){//创建表
		try{
			db.execSQL(sql);//执行SQL语句
		}catch(Exception e){
			e.printStackTrace();
		}		
	}
}
